<template>
	<view class="container">
		<view class="logo">
			<img :src="logo">
		</view>
		<uni-forms ref="dynamicForm" :model="user" class='form'>
			<uni-forms-item label="用户名" name="username">
				<uni-easyinput v-model="user.username" placeholder="请输入用户名" />
			</uni-forms-item>
		<uni-forms-item label="密码" name="password">
			<uni-easyinput v-model="user.password" type="password" placeholder="请输入用户名" />
		</uni-forms-item>
		</uni-forms>
		<view class="btn">
			<button class="btn_login" @click="login">登入</button>
		</view>
	</view>
</template>

<script>
	import { login,getUserInfo,idAttendance,idTown,idApprover } from '@/api/login.js'

	export default {
		// 获取时间
		data() {
			return {
				logo:require('../../static/logo.png'),
				user:{
					username:'',
					password:''
				},
			}
		},
		methods: {
			async login(){
				const res = await login(this.user)
				if(res.status == 0){
					uni.setStorageSync('token',res.token)
					const result = await getUserInfo()
					if(result.status == 0){
						uni.setStorageSync('userInfo',JSON.stringify(result.data))
						const res = await idAttendance(result.data)
						if(res.status == 0){
							uni.setStorageSync('attendanceInfo',JSON.stringify(res.data))
						}
						const response = await idTown(result.data)
						if(response.status == 0){
							uni.setStorageSync('townInfo',JSON.stringify(response.data))
						}
						const approver = await idApprover(result.data)
						if(approver.status == 0){
							uni.setStorageSync('approverInfo',JSON.stringify(approver.data))
						}
						
					}
					uni.showToast({
						title:'登入成功'
					})
					uni.switchTab({
						url: '/pages/home/home'
					});
					
				}
				
			}
		}
	}
</script>

<style lang="less" scoped>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
		.form{
			margin-top: 100rpx;
		}
		.logo{
			width: 400rpx;
			height: 400rpx;
			margin: auto;
			img{
				width: 100%;
				height: 100%;
			}
		}
		.btn{
			.btn_login{
				background-color: aqua;
				color:#ffffff
			}
		}
	}
</style>
